<template>
  <div>
    <div v-if="isIndexVisible">
      <adminindex />
    </div>
    <div v-if="isCompanyIndexVisible">
      <companyindex />
    </div>
  </div>
</template>

<script>
import { role } from '@/api/echarts/echart';
import adminindex from '@/views/system/companyinfo/adminindex';
import companyindex from '@/views/system/companyinfo/companyindex';

export default {
  components: {
    adminindex,
    companyindex,
  },
  data() {
    return {
      isIndexVisible: false, 
      isCompanyIndexVisible: false, 
    };
  },
  async mounted() {
    try {
      await this.isAuthorized();
    } catch (error) {
      console.error("角色验证失败", error);
    }
  },
  methods: {
    async isAuthorized() {
      try {
        const res = await role();
        const roles = res.data.role; // 假设返回的数据结构是这样
        console.log(roles);
        // 根据角色来判断显示哪个组件
        if (["管理员", "应聘者", "面试官"].includes(roles)) {
          this.isIndexVisible = true;
        } else if (roles === "公司") {
          this.isCompanyIndexVisible = true;
        }
      } catch (err) {
        console.error("角色获取失败", err);
        // 默认显示逻辑
        this.isIndexVisible = true;
      }
    },
  },
};
</script>



